import { requestToData, requestToExport, requestToStatus } from '@/api/commonHttp';

// 售价相关 - 模板导出
export const exportSaleTemplateService = (data, loadingFn) => {
  const { isSaleMultiUnit, uuid, tableData } = data;
  return requestToExport({
    url: `/sysback/salepirce/up/excel/export?isSaleMultiUnit=${isSaleMultiUnit}&uuid=${uuid}`,
    type: 'post',
    data: tableData,
    loadingFn
  });
}

// 售价相关 - 模板导出生成uuid的清除
export const deleteExportUuidService = (data) => {
  return requestToStatus({
    url: `/sysback/salepirce/up/excel/deleteCache?uuid=${data}`,
    type: 'get'
  });
}

// 售价相关 - 价格组设置 - 列表查询
export const initTypeUpAreaListService = (data, loadingFn) => requestToData({
  url: '/sysback/saletypeupdate/initTypeUpAreaList',
  type: 'post',
  data,
  loadingFn
});
// 售价相关 - 价格组设置 - 列表查询（修改价格组 - 单个productUuid）
export const echoSaleGroupAreaService = (data, loadingFn) => requestToData({
  url: `/sysback/saleprice/group/echoSaleGroupArea?productUuid=${data.productUuid}`,
  type: 'get',
  loadingFn
});

/* ----------------- 价格组参照关系设置-列表查询 ----------------- */
// 售价相关 - 价格组参照关系设置 - 列表查询（商品新增售价信息|待准入维护售价信息）
export const getByProductUuidService = (params, loadingFn) => requestToData({
  url: `/sysback/salepricesku/getByProductUuid?uuid=${params.uuid}`,
  type: 'post',
  data: params,
  loadingFn,
  isFormData: true
});
// 售价相关 - 价格组参照关系设置 - 列表查询
export const getByOperService = (params, loadingFn) => requestToData({
  url: `/sysback/salepricegrouptempbatchup/getByOper?uuid=${params.uuid}`,
  type: 'post',
  data: params.productUuids,
  loadingFn
});
// 售价相关 - 价格组参照关系设置 - 列表查询（修改价格组 - 单个productUuid）
export const echoSaleGroupService = (params, loadingFn) => requestToData({
  url: `/sysback/saleprice/group/echoSaleGroup?productUuid=${params.productUuid}&uuid=${params.uuid}`,
  type: 'get',
  loadingFn
});

/* ----------------- 提交价格组设置数据 ----------------- */
// 售价相关 - 商品新增售价|准入售价信息 - 提交价格组设置数据
export const submitPriceGroupByWaitingPriceService = (params, loadingFn) => requestToStatus({
  url: `/sysback/salepricesku/createGroupAndAreaRel?uuid=${params.uuid}`,
  type: 'post',
  data: params.data,
  loadingFn
});
// 售价相关 - 批量新增售价（单、多计量）|修改售价类型（单、多计量）- 提交价格组设置数据
export const submitPriceGroupByWaitedPriceService = (params, loadingFn) => requestToStatus({
  url: `/sysback/salepriceskubatchadd/createGroupAndAreaRelRedis?uuid=${params.uuid}`,
  type: 'post',
  data: params.data,
  loadingFn
});
// 售价相关 - 修改价格组 - 价格组设置 - 提交价格组设置数据
export const submitPriceGroupByEditGroupService = (params, loadingFn) => requestToStatus({
  url: `/sysback/salepricegrouptempbatchup/createGroupAndAreaRelRedis?uuid=${params.uuid}`,
  type: 'post',
  data: params.data,
  loadingFn
});

/* ----------------- 提交价格组参照关系设置数据 ----------------- */
// 售价相关 - 准入新增售价 - 提交价格组参照关系设置数据
export const submitGroupReferByWaitingPriceService = (params, loadingFn) => requestToStatus({
  url: '/sysback/salepricesku/updateGroupList',
  type: 'post',
  data: params.data,
  loadingFn
});
// 售价相关 - 批量新增售价（单、多计量）- 提交价格组参照关系设置数据
export const submitGroupReferByBatchAddPriceService = (params, loadingFn) => requestToData({
  url: `/sysback/salepriceskubatchadd/getCalculatedSalePriceSku?uuid=${params.uuid}&isUseOther=0`,
  type: 'post',
  data: params.data,
  loadingFn
});
// 售价相关 - 修改售价类型（单、多计量）- 提交价格组参照关系设置数据
export const submitGroupReferByEditPriceTypeService = (params, loadingFn) => requestToStatus({
  url: `/sysback/saletypeupdate/updateGroupListForSaleTypeUpdate?uuid=${params.uuid}`,
  type: 'post',
  data: params.data,
  loadingFn
});
// 售价相关 - 修改价格组 - 提交价格组参照关系设置数据
export const submitGroupReferByEditGroupService = (params, loadingFn) => requestToStatus({
  url: `/sysback/salepricegrouptempbatchup/updateGroupList?uuid=${params.uuid}`,
  type: 'post',
  data: params.data,
  loadingFn
});

// 售价相关 - 价格计算 - 单独计算售价
export const countSinglePriceService = (data, loadingFn) => requestToData({
  url: '/sysback/salepriceskuupdate/calculateUpInput',
  type: 'post',
  data,
  loadingFn
});

// 售价相关 - 获取售价类型
export const querySaleTypeService = (data, target) => requestToData({
  url: '/sysback/salepricesku/querySaleType',
  type: 'get',
  data,
  target
});
